package com.bupt.algorithm;

import com.bupt.basic.IBasicNetWork;
import com.bupt.entity.Limit;

import java.io.Serializable;
import java.util.*;

public class SystemLimit implements Limit, Serializable {
    private static final long serialVersionUID = -7355854895827893339L;
    private String id;//系统的ID
    private String name;//系统名称
    private List<IBasicNetWork.BasicLink> links = new ArrayList<>();//在同一个系统中的链路,有序排列
    private Set<IBasicNetWork.BasicLink> linkSet = new HashSet<>();
    private Set<IBasicNetWork.BasicLink> nodes = new HashSet<>();//在系统中的节点

    public SystemLimit(String id, String name){
        this.id = id;
        this.name = name;
    }

    public SystemLimit(String name){
        id = UUID.randomUUID().toString().replace("-","");
        this.name = name;
    }

    public SystemLimit(){
        id = UUID.randomUUID().toString().replace("-","");
    }

    /*public SystemLimit add(IBasicNetWork.BasicLink link){
        links.add(link);
        linkSet.add(link);
        nodes.add(link.getFromNode());
        nodes.add(link.getToNode());
        return this;
    }

    public SystemLimit add(List<BasicLink> links){
        this.links.addAll(links);
        for(BasicLink link: links){
            linkSet.add(link);
            nodes.add(link.getFromNode());
            nodes.add(link.getToNode());
        }
        return this;
    }*/

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public List<IBasicNetWork.BasicLink> getLinks() {
        return links;
    }

    public boolean inSystem(IBasicNetWork.BasicLink link){
        return linkSet.contains(link);
    }
    public boolean inSystem(IBasicNetWork.BasicNode node){
        return nodes.contains(node);
    }
    public boolean inTheSomeSystem( IBasicNetWork.BasicNode node1, IBasicNetWork.BasicNode node2){
        return (nodes.contains(node1) && nodes.contains(node2));
    }
}